<template>
  <view class="comBox">
    <sickTitleCom></sickTitleCom>
    <view class="body">
      <view class="name titleBold">您的糖化检查结果（非必填）</view>
      <view class="inputBox">
        <span class="name lineHeight86">糖化血红蛋白</span>
        <input
          id="SBP"
          v-model="mainData.HBALC"
          type="digit"
          class="uni-input lineHeight86"
          name="HBALC"
          placeholder-class="phcolor"
        />
        <view class="unit">%</view>
        <view class="clear"></view>
      </view>
      <!-- 下一题上一题按钮 -->
      <nextProBtnCom @nextBtn="nextBtn" @proBtn="proBtn"></nextProBtnCom>
    </view>
  </view>
</template>

<script>
import { decimalOne, checkBetween } from '@/common/assessKeyCheck';
import nextProBtnCom from '@/components/nextProButton';
import sickTitleCom from './sickTitleCom';
import { mapGetters } from 'vuex';
export default {
  components: {
    // 上一题下一题组件
    nextProBtnCom,
    sickTitleCom
  },
  data() {
    return {
      mainData: {
        HBALC: ''
      },
      array: ['umol/L', 'mg/dl'],
      index: 0
    };
  },
  computed: {
    ...mapGetters(['active', 'assessForm', 'isHaveDiabetes'])
  },
  mounted() {},
  methods: {
    nextBtn() {
      // 先校验数据
      // let isPassAuth = true;
      // ① 必填校验
      // Object.keys(this.mainData).forEach((key) => {
      //   if (!this.mainData[key] && this.isHaveDiabetes) {
      //     uni.showToast({ title: `请输入糖化血红蛋白`, icon: 'none' });
      //     isPassAuth = false;
      //     return;
      //   }
      // });
      // if (!isPassAuth) {
      //   return false;
      // }
      // ②录入值格式校验
      if (decimalOne(this.mainData.HBALC)) {
        uni.showToast({
          title: `糖化血红蛋白数据错误，请重新输入`,
          icon: 'none'
        });
        return false;
      }
      if (checkBetween(this.mainData.HBALC, '糖化血红蛋白', 3, 20)) {
        uni.showToast({
          title: `糖化血红蛋白数据错误，请重新输入`,
          icon: 'none'
        });
        return false;
      }
      // 提交vuex assessForm值
      let submitData = this.assessForm;
      let curActive = this.active + 1;
      Object.keys(this.mainData).forEach((key) => {
        submitData[key] = this.mainData[key];
      });
      submitData.scrUnit = this.index + 1;
      this.$store.commit('assessQuestion/SET_ASSESSFORM', submitData);
      this.$store.commit('assessQuestion/SET_ACTIVE', curActive);
    },
    proBtn() {
      let curActive = this.active - 1;
      this.$store.commit('assessQuestion/SET_ACTIVE', curActive);
    },
    bindPickerChange: function (e) {
      this.index = e.target.value;
    }
  }
};
</script>
